package icu.makka.yygh.msm.controller;

import icu.makka.yygh.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.websocket.server.PathParam;
import java.util.concurrent.TimeUnit;

@Slf4j
@RestController
@Api(tags = "将验证码存入redis")
@RequestMapping("/api/saveSms")
public class SaveCodeController {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @ApiOperation(value = "存入验证码")
    @PostMapping("/{phone}/{code}")
    public Result save(@PathVariable("phone") String phone,
                       @PathVariable("code") String code) {
        redisTemplate.opsForValue().set(phone, code, 2, TimeUnit.MINUTES);
        return Result.ok();
    }
}
